from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-05-31 14:03:09.173324
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 31, May, 2022
Time: 14:03:14
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.4815
Nobs: 673.000 HQIC: -49.8512
Log likelihood: 8349.04 FPE: 1.77189e-22
AIC: -50.0848 Det(Omega_mle): 1.55163e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.306445 0.059489 5.151 0.000
L1.Burgenland 0.107014 0.038508 2.779 0.005
L1.Kärnten -0.109998 0.020253 -5.431 0.000
L1.Niederösterreich 0.197677 0.080125 2.467 0.014
L1.Oberösterreich 0.127348 0.079278 1.606 0.108
L1.Salzburg 0.255623 0.040965 6.240 0.000
L1.Steiermark 0.044689 0.053674 0.833 0.405
L1.Tirol 0.104822 0.043460 2.412 0.016
L1.Vorarlberg -0.061370 0.038341 -1.601 0.109
L1.Wien 0.032507 0.070220 0.463 0.643
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.040487 0.126476 0.320 0.749
L1.Burgenland -0.030960 0.081870 -0.378 0.705
L1.Kärnten 0.040392 0.043059 0.938 0.348
L1.Niederösterreich -0.182818 0.170348 -1.073 0.283
L1.Oberösterreich 0.444326 0.168547 2.636 0.008
L1.Salzburg 0.285536 0.087092 3.279 0.001
L1.Steiermark 0.108972 0.114113 0.955 0.340
L1.Tirol 0.313875 0.092396 3.397 0.001
L1.Vorarlberg 0.023708 0.081514 0.291 0.771
L1.Wien -0.035975 0.149291 -0.241 0.810
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.185668 0.030544 6.079 0.000
L1.Burgenland 0.089190 0.019771 4.511 0.000
L1.Kärnten -0.007934 0.010399 -0.763 0.445
L1.Niederösterreich 0.256561 0.041139 6.237 0.000
L1.Oberösterreich 0.152917 0.040704 3.757 0.000
L1.Salzburg 0.043734 0.021033 2.079 0.038
L1.Steiermark 0.024308 0.027558 0.882 0.378
L1.Tirol 0.085445 0.022313 3.829 0.000
L1.Vorarlberg 0.053432 0.019685 2.714 0.007
L1.Wien 0.117757 0.036053 3.266 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.109959 0.030638 3.589 0.000
L1.Burgenland 0.044661 0.019832 2.252 0.024
L1.Kärnten -0.014155 0.010431 -1.357 0.175
L1.Niederösterreich 0.183672 0.041265 4.451 0.000
L1.Oberösterreich 0.325930 0.040829 7.983 0.000
L1.Salzburg 0.102100 0.021097 4.839 0.000
L1.Steiermark 0.109135 0.027643 3.948 0.000
L1.Tirol 0.097303 0.022382 4.347 0.000
L1.Vorarlberg 0.061695 0.019746 3.124 0.002
L1.Wien -0.021299 0.036164 -0.589 0.556
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.119074 0.056894 2.093 0.036
L1.Burgenland -0.045535 0.036828 -1.236 0.216
L1.Kärnten -0.046283 0.019370 -2.389 0.017
L1.Niederösterreich 0.143318 0.076629 1.870 0.061
L1.Oberösterreich 0.159993 0.075819 2.110 0.035
L1.Salzburg 0.281661 0.039178 7.189 0.000
L1.Steiermark 0.053271 0.051332 1.038 0.299
L1.Tirol 0.165621 0.041563 3.985 0.000
L1.Vorarlberg 0.096318 0.036668 2.627 0.009
L1.Wien 0.074894 0.067157 1.115 0.265
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.058719 0.044955 1.306 0.192
L1.Burgenland 0.031042 0.029100 1.067 0.286
L1.Kärnten 0.051624 0.015305 3.373 0.001
L1.Niederösterreich 0.204653 0.060550 3.380 0.001
L1.Oberösterreich 0.316855 0.059909 5.289 0.000
L1.Salzburg 0.041774 0.030957 1.349 0.177
L1.Steiermark 0.009065 0.040561 0.223 0.823
L1.Tirol 0.131497 0.032842 4.004 0.000
L1.Vorarlberg 0.067480 0.028974 2.329 0.020
L1.Wien 0.087848 0.053065 1.655 0.098
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.167980 0.053732 3.126 0.002
L1.Burgenland 0.006735 0.034782 0.194 0.846
L1.Kärnten -0.064878 0.018293 -3.547 0.000
L1.Niederösterreich -0.091329 0.072371 -1.262 0.207
L1.Oberösterreich 0.200707 0.071606 2.803 0.005
L1.Salzburg 0.055242 0.037001 1.493 0.135
L1.Steiermark 0.240246 0.048480 4.956 0.000
L1.Tirol 0.501901 0.039254 12.786 0.000
L1.Vorarlberg 0.060206 0.034630 1.739 0.082
L1.Wien -0.074657 0.063425 -1.177 0.239
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.150628 0.059783 2.520 0.012
L1.Burgenland 0.002393 0.038698 0.062 0.951
L1.Kärnten 0.060775 0.020353 2.986 0.003
L1.Niederösterreich 0.186854 0.080521 2.321 0.020
L1.Oberösterreich -0.061565 0.079669 -0.773 0.440
L1.Salzburg 0.207294 0.041167 5.035 0.000
L1.Steiermark 0.133462 0.053939 2.474 0.013
L1.Tirol 0.070116 0.043674 1.605 0.108
L1.Vorarlberg 0.143434 0.038530 3.723 0.000
L1.Wien 0.108326 0.070567 1.535 0.125
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.375006 0.035279 10.630 0.000
L1.Burgenland -0.001417 0.022837 -0.062 0.951
L1.Kärnten -0.022062 0.012011 -1.837 0.066
L1.Niederösterreich 0.215313 0.047517 4.531 0.000
L1.Oberösterreich 0.224871 0.047014 4.783 0.000
L1.Salzburg 0.039987 0.024293 1.646 0.100
L1.Steiermark -0.015566 0.031830 -0.489 0.625
L1.Tirol 0.096151 0.025773 3.731 0.000
L1.Vorarlberg 0.055379 0.022737 2.436 0.015
L1.Wien 0.034060 0.041643 0.818 0.413
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.037949 0.121077 0.177406 0.144622 0.103843 0.087452 0.039918 0.213947
Kärnten 0.037949 1.000000 -0.018271 0.136049 0.052850 0.092217 0.441669 -0.059041 0.094900
Niederösterreich 0.121077 -0.018271 1.000000 0.325176 0.132258 0.284742 0.079435 0.164340 0.303700
Oberösterreich 0.177406 0.136049 0.325176 1.000000 0.221570 0.312526 0.171834 0.152833 0.255366
Salzburg 0.144622 0.052850 0.132258 0.221570 1.000000 0.131637 0.100295 0.116649 0.132619
Steiermark 0.103843 0.092217 0.284742 0.312526 0.131637 1.000000 0.143323 0.121283 0.056546
Tirol 0.087452 0.441669 0.079435 0.171834 0.100295 0.143323 1.000000 0.074729 0.151584
Vorarlberg 0.039918 -0.059041 0.164340 0.152833 0.116649 0.121283 0.074729 1.000000 0.010438
Wien 0.213947 0.094900 0.303700 0.255366 0.132619 0.056546 0.151584 0.010438 1.000000